package com.huike.business.service.impl;


import com.huike.business.domain.TbBusiness;
import com.huike.business.domain.TbBusinessTrackRecord;
import com.huike.business.domain.vo.BusinessTrackVo;
import com.huike.business.mapper.TbBusinessMapper;
import com.huike.business.mapper.TbBusinessTrackRecordMapper;
import com.huike.business.service.ITbBusinessTrackRecordService;
import com.huike.clues.domain.TbClue;
import com.huike.clues.service.ISysDictDataService;
import com.huike.common.utils.DateUtils;
import com.huike.common.utils.SecurityUtils;
import com.huike.common.utils.bean.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 商机跟进记录Service业务层处理
 */
@Service
public class TbBusinessTrackRecordServiceImpl implements ITbBusinessTrackRecordService {

    @Autowired
    private TbBusinessTrackRecordMapper recordMapper;
    @Autowired
    private TbBusinessMapper businessMapper;
    @Autowired
    private ISysDictDataService sysDictDataService;


    /**
     * 新增商机跟进记录
     */
    @Override
    public void add(BusinessTrackVo businessTrackVo) {
        TbBusiness tbBusiness = new TbBusiness();
        tbBusiness.setStatus(TbBusiness.StatusType.FOLLOWING.getValue());
        tbBusiness.setId(businessTrackVo.getBusinessId());
        BeanUtils.copyProperties(businessTrackVo,tbBusiness);
        businessMapper.updateTbBusiness(tbBusiness);

        TbBusinessTrackRecord businessTrackRecord = new TbBusinessTrackRecord();
        businessTrackRecord.setBusinessId(businessTrackVo.getBusinessId());
        businessTrackRecord.setCreateBy(SecurityUtils.getUsername());
        businessTrackRecord.setKeyItems(businessTrackVo.getKeyItems());
        businessTrackRecord.setRecord(businessTrackVo.getRecord());
        businessTrackRecord.setCreateTime(new Date());
        businessTrackRecord.setTrackStatus(businessTrackVo.getTrackStatus());
        businessTrackRecord.setNextTime(businessTrackVo.getNextTime());
        recordMapper.add(businessTrackRecord);
    }

    /**
     * 查询商机跟进记录列表
     */
    @Override
    public List<TbBusinessTrackRecord> list(Long businessId) {
        List<TbBusinessTrackRecord> list = recordMapper.list(businessId);
        return list;
    }
}
